/*
This program generates the conjoint data and produces conjoint 
results shown in Figure 2, Figure 3, Figure A-4, and Table A-5 and A-6 of 
the paper and online appendix 
*/

clear all
set more off
set matsize 800
set memory 200m

*cd "$localdir/Data"
*gl output "$localdir/Output"

cd "C:\Users\clare\Documents\PostDoc @UofT\Methods paper\Papers for reanalysis\Jensen et al replication material\dataverse_files\fordataverse\Data"
gl output "C:\Users\clare\Documents\PostDoc @UofT\Methods paper\Papers for reanalysis\Jensen et al replication material\dataverse_files\fordataverse\Output_Clareta"

***** Conjoint on pooled sample - All MSAs together *****

*** Load analysis data
use msa_survey_indiv, clear


*** Generate conjoint data 

keep caseid q16* //keep only these vars > the conjoint vars 

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey

merge m:1 caseid using msa_survey_indiv
drop _merge

save "all_conjoint.dta", replace


*** Graphs and tables
use "all_conjoint.dta", clear
set scheme s1mono // Graph layout

* Short value labels
lab def educ 1 "Charter schools" 2 "Vouchers to schools" 3 "Free pre-school" 4 "Pay teachers more" 5 "Keep current" 
lab def hieduc 1 "Community colleges" 2 "Local public universities" 3 "Technical vocational training" 4 "Student grant programs" 5 "Keep current" 
lab def invest 1 "Attract new businesses" 2 "Stimulate existing companies" 3 "Encourage investment charities" 4 "Keep current" 
lab def gov 1 "Consolidate local government" 2 "More power to the state" 3 "Keep current"
lab def workers 1 "Limit unions' power" 2 "Expand unions' power" 3 "Worker training vouchers" 4 "Tax breaks to entrepreneurs" 5 "Keep current"
lab def local 1 "Affordable housing" 2 "Public transportation" 3 "Safety and crime prevention" 4 "Keep current"   
lab values educ educ
lab values hieduc hieduc
lab values invest invest
lab values gov gov
lab values workers workers
lab values local local

* Figure and table with pooled conjoint results
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight], cluster(caseid)
estimate store baseline_w
local n_baseline = e(N)
*outreg2 using  "$output/tableA5.xls", nocons nor side replace ctitle(Estimate) tex(frag) bdec(3) label addstat(Root MSE, e(rmse),Respondents, e(N_clust))

coefplot baseline_w, title(/*"All Cities"*/"") mcolor(black) ciopts(lcolor(black) lwidth(thin)) xlabel(-0.15(.05) 0.15) omitted base xline(0) ///
headings(2.educ = "{bf:Education}" 3.hieduc = "{bf:Higher Education}" 2.invest = "{bf:Investment & Taxes}" 2.gov = "{bf:Governance}" ///
3.workers = "{bf:Workers & Entrepreneurs}" 2.local = "{bf:Local Services}") ///
drop(_cons 5.educ 5.hieduc 4.invest 3.gov 5.workers 4.local) ///
order(2.invest 3.invest 1.invest 3.workers 4.workers 1.workers 2.workers 2.local 3.local 1.local 2.gov 1.gov 2.educ 4.educ 3.educ 1.educ 3.hieduc 4.hieduc 2.hieduc 1.hieduc) ///
xscale(titlegap(*6)) yscale(titlegap(*3)) ///
ylabel(, labsize(medium)) xtitle("Change in Pr(Development Plan Selected)") ytitle("") xsize(5) ysize(7) scale(.6)    
graph export "$output/fig2_a.pdf", replace
graph export "$output/fig2_a.eps", replace


* Table with strong D/R interaction
g strong_DR = .
replace  strong_DR = 0 if strong_dem == 1
replace  strong_DR = 1 if strong_rep == 1
lab def strong_DR 0 "Strong Democrat" 1 "Strong Republican" 
lab val strong_DR strong_DR

* Regressions 
* Everyone together
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight], cluster(caseid)

* Democrats
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local if strong_DR == 0 [pweight=weight], cluster(caseid)

* Republicans
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local if strong_DR == 1 [pweight=weight], cluster(caseid)

* Interactions
reg plan_chosen (ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local)##i.strong_DR [pweight=weight], cluster(caseid)
outreg2 using "$localdir/Output/tableA6.tex", replace tex(frag) labe // in Table A6 in the SM they only report the coeffs on the interactions (not the full table)

save "all_conjoint.dta", replace

***** Conjoint for each MSA separately *****

*** Conjoint analysis by MSA
foreach i of numlist 1/8 {

*** Load analysis data
use msa_survey_indiv, clear

keep if msa==`i'
tab msa

local forlab: value label msa
local label: label `forlab' `i'
di "`label'"

*** Generate conjoint data 

keep caseid q16*

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey and save MSA data

merge m:1 caseid using msa_survey_indiv
drop _merge
keep if msa==`i'

save "`label'_conjoint.dta", replace
}


*** Graphs

* All individual city estimates in one graph
use "Charlotte_conjoint.dta", clear
append using "Cleveland_conjoint.dta" "Houston_conjoint.dta" "Indianapolis_conjoint.dta" ///
"Memphis_conjoint.dta" "Rochester_conjoint.dta" "St. Louis_conjoint.dta" "Seattle_conjoint.dta", generate(data)
set scheme s1mono // Graph layout

* Short value labels
lab def educ 1 "Charter schools" 2 "Vouchers to schools" 3 "Free pre-school" 4 "Pay teachers more" 5 "Keep current" 
lab def hieduc 1 "Community colleges" 2 "Local public universities" 3 "Technical vocational training" 4 "Student grant programs" 5 "Keep current" 
lab def invest 1 "Attract new businesses" 2 "Stimulate existing companies" 3 "Encourage investment charities" 4 "Keep current" 
lab def gov 1 "Consolidate local government" 2 "More power to the state" 3 "Keep current"
lab def workers 1 "Limit unions' power" 2 "Expand unions' power" 3 "Worker training vouchers" 4 "Tax breaks to entrepreneurs" 5 "Keep current"
lab def local 1 "Affordable housing" 2 "Public transportation" 3 "Safety and crime prevention" 4 "Keep current"   
lab values educ educ
lab values hieduc hieduc
lab values invest invest
lab values gov gov
lab values workers workers
lab values local local

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==0, cluster(caseid)
estimate store baseline_w0
local n_baseline0 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==1, cluster(caseid)
estimate store baseline_w1
local n_baseline1 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==2, cluster(caseid)
estimate store baseline_w2
local n_baseline2 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==3, cluster(caseid)
estimate store baseline_w3
local n_baseline2 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==4, cluster(caseid)
estimate store baseline_w4
local n_baseline2 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==5, cluster(caseid)
estimate store baseline_w5
local n_baseline2 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==6, cluster(caseid)
estimate store baseline_w6
local n_baseline2 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==7, cluster(caseid)
estimate store baseline_w7
local n_baseline2 = e(N)

coefplot ///
(baseline_w0, label("Charlotte") msize(*1.5) msymbol(X) mcolor(black) mfcolor(black) noci) ///
(baseline_w1, label("Cleveland") msize(*1.5) msymbol(X) mcolor(blue) mfcolor(blue) noci) ///
(baseline_w2, label("Houston") msize(*1.5) msymbol(X) mcolor(green) mfcolor(green) noci) ///
(baseline_w3, label("Indianapolis") msize(*1.5) msymbol(X) mcolor(red) mfcolor(red) noci) ///
(baseline_w4, label("Memphis") msize(*1.5) msymbol(X) mcolor(magenta) mfcolor(magenta) noci) ///
(baseline_w5, label("Rochester") msize(*1.5) msymbol(X) mcolor(sandb) mfcolor(sandb) noci) ///
(baseline_w6, label("St. Louis") msize(*1.5) msymbol(X) mcolor(eltblue) mfcolor(eltblue) noci) ///
(baseline_w7, label("Seattle") msize(*1.5) msymbol(X) mcolor(gs10) mfcolor(gs10) noci), ///
legend(cols(4) region(fcolor(white) lcolor(white)) size(medium)) ///
title(/*"Individual MSAs"*/"") xlabel(-0.15(.05) 0.15) omitted base xline(0) ///
headings(2.educ = "{bf:Education}" 3.hieduc = "{bf:Higher Education}" 2.invest = "{bf:Investment & Taxes}" 2.gov = "{bf:Governance}" ///
3.workers = "{bf:Workers & Entrepreneurs}" 2.local = "{bf:Local Services}") ///
drop(_cons 5.educ 5.hieduc 4.invest 3.gov 5.workers 4.local) ///
order(2.invest 3.invest 1.invest 3.workers 4.workers 1.workers 2.workers 2.local 3.local 1.local 2.gov 1.gov 2.educ 4.educ 3.educ 1.educ 3.hieduc 4.hieduc 2.hieduc 1.hieduc) ///
ylabel(, labsize(medium)) xtitle("Change in Pr(Development Plan Selected)") ytitle("") xsize(5) ysize(7) scale(.6)  
graph export "$output/fig2_b.pdf", replace
graph export "$output/fig2_b.eps", replace






***** Conjoint on pooled sample, by party id - strong partisans *****

*** Strong democrats
global var "strong_democrat"

*** Load data and restrict sample
use msa_survey_indiv, clear

keep if $var==1 //keeping only strong democrats

*** Generate conjoint data

keep caseid q16*

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey and save data

merge m:1 caseid using msa_survey_indiv
drop _merge
keep if $var==1

save "strong_democrat_conjoint.dta", replace



*** Strong republican
global var "strong_republican"

*** Load data and restrict sample
use msa_survey_indiv, clear

keep if $var==1

*** Generate conjoint data

keep caseid q16*

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey and save data

merge m:1 caseid using msa_survey_indiv
drop _merge
keep if $var==1

save "strong_republican_conjoint.dta", replace


*** Partisan conjoints in same graph

* Strong D and strong R data
use "strong_democrat_conjoint.dta", clear
append using "strong_republican_conjoint.dta", generate(data) //adding the strong republican data 
set scheme s1mono // Graph layout

* Short value labels
lab def educ 1 "Charter schools" 2 "Vouchers to schools" 3 "Free pre-school" 4 "Pay teachers more" 5 "Keep current" 
lab def hieduc 1 "Community colleges" 2 "Local public universities" 3 "Technical vocational training" 4 "Student grant programs" 5 "Keep current" 
lab def invest 1 "Attract new businesses" 2 "Stimulate existing companies" 3 "Encourage investment charities" 4 "Keep current" 
lab def gov 1 "Consolidate local government" 2 "More power to the state" 3 "Keep current"
lab def workers 1 "Limit unions' power" 2 "Expand unions' power" 3 "Worker training vouchers" 4 "Tax breaks to entrepreneurs" 5 "Keep current"
lab def local 1 "Affordable housing" 2 "Public transportation" 3 "Safety and crime prevention" 4 "Keep current"   
lab values educ educ
lab values hieduc hieduc
lab values invest invest
lab values gov gov
lab values workers workers
lab values local local

* Strong Democrats
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==0, cluster(caseid)
estimate store baseline_w0
local n_baseline0 = e(N)

* Strong Republicans
reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==1, cluster(caseid)
estimate store baseline_w1
local n_baseline1 = e(N)

coefplot ///
(baseline_w0, label("Strong Democrats") msymbol(circle) mcolor(black) mfcolor(none) ciopts(lcolor(black) lwidth(thin))) ///
(baseline_w1, label("Strong Republicans") msymbol(circle) mcolor(black) ciopts(lcolor(black) lwidth(thin))), ///
legend(cols(3) region(fcolor(white) lcolor(white)) size(medium)) ///
title(/*"Strong Democrats and Republicans"*/"") xlabel(-0.15(.05) 0.15) omitted base xline(0) ///
headings(2.educ = "{bf:Education}" 3.hieduc = "{bf:Higher Education}" 2.invest = "{bf:Investment & Taxes}" 2.gov = "{bf:Governance}" ///
3.workers = "{bf:Workers & Entrepreneurs}" 2.local = "{bf:Local Services}") ///
drop(_cons 5.educ 5.hieduc 4.invest 3.gov 5.workers 4.local) ///
order(2.invest 3.invest 1.invest 3.workers 4.workers 1.workers 2.workers 2.local 3.local 1.local 2.gov 1.gov 2.educ 4.educ 3.educ 1.educ 3.hieduc 4.hieduc 2.hieduc 1.hieduc) ///
ylabel(, labsize(medium)) xtitle("Change in Pr(Development Plan Selected)") ytitle("") xsize(5) ysize(7) scale(.6)  
graph export "$output/fig3.pdf", replace
graph export "$output/fig3.eps", replace


***** Conjoint on pooled sample, by party id - standard question ("Do you think of yourself as a...")  *****

*** Democrat
global var "democrat"

*** Load data and restrict sample
use msa_survey_indiv, clear

keep if $var==1

*** Generate conjoint data

keep caseid q16*

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey and save data

merge m:1 caseid using msa_survey_indiv
drop _merge
keep if $var==1

save "democrat_conjoint.dta", replace


*** Republican
global var "republican"

*** Load data and restrict sample
use msa_survey_indiv, clear

keep if $var==1

*** Generate conjoint data

keep caseid q16*

* Number of dimensions: 6
* Number of comparisons: 5
* Number of plans per comparison: 2
* Final conjoint data: 10 rows per respondent, with infomation about 6 dimensions and whether the plan was chosen

* Make 5 comparisions into rows per policy dimension
foreach policy in educ hieduc invest gov workers local {
rename q16a_1_`policy' `policy'11
rename q16b_1_`policy' `policy'12
rename q16c_1_`policy' `policy'13
rename q16d_1_`policy' `policy'14
rename q16e_1_`policy' `policy'15
rename q16a_2_`policy' `policy'21
rename q16b_2_`policy' `policy'22
rename q16c_2_`policy' `policy'23
rename q16d_2_`policy' `policy'24
rename q16e_2_`policy' `policy'25
}

reshape long educ1 hieduc1 invest1 gov1 workers1 local1 educ2 hieduc2 invest2 gov2 workers2 local2, i(caseid) j(table)

* Make 2 rows for each 5 comparisons, for each 6 policy dimensions
sort caseid table
g count=_n

reshape long educ hieduc invest gov workers local, i(count) j(plan)
drop count

rename q16_a table1_choice
rename q16_b table2_choice
rename q16_c table3_choice
rename q16_d table4_choice
rename q16_e table5_choice

g plan_chosen=.
forval t=1/5 {
replace plan_chosen=1 if table==`t' & plan==1 & table`t'_choice==1 
replace plan_chosen=0 if table==`t' & plan==1 & table`t'_choice==2
replace plan_chosen=1 if table==`t' & plan==2 & table`t'_choice==2 
replace plan_chosen=0 if table==`t' & plan==2 & table`t'_choice==1 
}

drop table1_choice- table5_choice


*** Merge with other information from the survey and save data

merge m:1 caseid using msa_survey_indiv
drop _merge
keep if $var==1

save "republican_conjoint.dta", replace



*** Partisan conjoints in same graph

* D and R data
use "democrat_conjoint.dta", clear
append using "republican_conjoint.dta", generate(data)
set scheme s1mono // Graph layout

* Short value labels
lab def educ 1 "Charter schools" 2 "Vouchers to schools" 3 "Free pre-school" 4 "Pay teachers more" 5 "Keep current" 
lab def hieduc 1 "Community colleges" 2 "Local public universities" 3 "Technical vocational training" 4 "Student grant programs" 5 "Keep current" 
lab def invest 1 "Attract new businesses" 2 "Stimulate existing companies" 3 "Encourage investment charities" 4 "Keep current" 
lab def gov 1 "Consolidate local government" 2 "More power to the state" 3 "Keep current"
lab def workers 1 "Limit unions' power" 2 "Expand unions' power" 3 "Worker training vouchers" 4 "Tax breaks to entrepreneurs" 5 "Keep current"
lab def local 1 "Affordable housing" 2 "Public transportation" 3 "Safety and crime prevention" 4 "Keep current"   
lab values educ educ
lab values hieduc hieduc
lab values invest invest
lab values gov gov
lab values workers workers
lab values local local

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==0, cluster(caseid)
estimate store baseline_w0
local n_baseline0 = e(N)

reg plan_chosen ib5.educ ib5.hieduc ib4.invest ib3.gov ib5.workers ib4.local [pweight=weight] if data==1, cluster(caseid)
estimate store baseline_w1
local n_baseline1 = e(N)

coefplot ///
(baseline_w0, label("Democrats") msymbol(circle) mcolor(black) mfcolor(none) ciopts(lcolor(black) lwidth(thin))) ///
(baseline_w1, label("Republicans") msymbol(circle) mcolor(black) ciopts(lcolor(black) lwidth(thin))), ///
legend(cols(3) region(fcolor(white) lcolor(white)) size(medium)) ///
title(""/*"Democrats and Republicans"*/) xlabel(-0.15(.05) 0.15) omitted base xline(0) ///
headings(2.educ = "{bf:Education}" 3.hieduc = "{bf:Higher Education}" 2.invest = "{bf:Investment & Taxes}" 2.gov = "{bf:Governance}" ///
3.workers = "{bf:Workers & Entrepreneurs}" 2.local = "{bf:Local Services}") ///
drop(_cons 5.educ 5.hieduc 4.invest 3.gov 5.workers 4.local) ///
order(2.invest 3.invest 1.invest 3.workers 4.workers 1.workers 2.workers 2.local 3.local 1.local 2.gov 1.gov 2.educ 4.educ 3.educ 1.educ 3.hieduc 4.hieduc 2.hieduc 1.hieduc) ///
ylabel(, labsize(medium)) xtitle("Change in Pr(Development Plan Selected)") ytitle("") xsize(5) ysize(7) scale(.6)  
graph export "$output/figA4.pdf", replace
graph export "$output/figA4.eps", replace

